package com.zzzyh.blogbyspring.mapper;

import com.zzzyh.blogbyspring.pojo.BlogInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogMapper {

    @Select("select * from blog where delete_flag = 0")
    List<BlogInfo> getBlogInfoList();

    @Select("select * from blog where id = #{id} and delete_flag = 0")
    BlogInfo getBlogInfoById(Integer id);


    @Update("update blog set title = #{title}, " +
            "content = #{content}, " +
            "user_id = #{userId} " +
            "where id = #{id}")
    Integer updateBlogInfo(BlogInfo blogInfo);

    @Delete("update blog set delete_flag = 1 where id = #{id}")
    Integer deleteBlogInfo(Integer id);

    @Insert("insert into blog(title, content, user_id) " +
            "values(#{title}, #{content}, #{userId})")
    Integer addBlogInfo(BlogInfo blogInfo);

    @Select("SELECT user_id FROM blog WHERE id = #{blogId}")
    Integer getUidByBlogId(Integer blogId);
}
